package com.tanhua.server.controller;

import com.tanhua.server.service.TestSoulService;
import com.tanhua.server.vo.AnswerList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("testSoul")
public class TestSoulController {

    @Autowired
    TestSoulService testSoulService;
    /**
     * 查询问卷列表
     */
    @GetMapping
    public ResponseEntity getQuestion() {
        try {
            return testSoulService.getQuestion();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 提交试卷
     */
    @PostMapping
    public ResponseEntity submitPaper(@RequestBody AnswerList answers) {
        try {
            return testSoulService.submitPaper(answers);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 查询报告
     */
    @GetMapping("report/{id}")
    public ResponseEntity getReport(@PathVariable("id") String reportId) {
        try {
            return testSoulService.getReport(reportId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
